clear all
set more off, permanently

save  "...\PADDD_impact.dta"

***************************** prepare data ************************************

*** pixels reduced in size in 2012 
gen enacR_12=1 if enacR_0912==1 & year_PADDD==2012
replace enacR_12=0 if enacR_0912==0

*before their reduction
gen R12protected2000=1 if Rprotected2000==1 & year_PADDD==2012
replace R12protected2000=0 if Rprotected2000==0 

*** pixels reduced in size in 2010 
gen enacR_10=1 if enacR_0912==1 & year_PADDD==2010
replace enacR_10=0 if enacR_0912==0

merge m:m PADDD using  "C...\desigPA.dta", gen(mergedesig)
gen desig=1 if Designation=="Federal"
replace desig=1 if Designation=="federal"
replace desig=2 if Designation=="State"
replace desig=2 if Designation=="state"
bysort ID1: fillmissing desig, with(any)
drop mergedesig

*state 
gen enacRS_10=enacR_10
replace enacRS_10=. if (enacR_10==1 & desig!=2)

*before their reduction
gen R10protected2000=1 if Rprotected2000==1 & year_PADDD==2010
replace R10protected2000=0 if Rprotected2000==0 

*** pixels reduced in size in 2009 
gen enacR_09=1 if enacR_0912==1 & year_PADDD==2009
replace enacR_09=0 if enacR_0912==0
gen R09protected2000=1 if Rprotected2000==1 & year_PADDD==2009
replace R09protected2000=0 if Rprotected2000==0 

*********************** descriptive statistics *******************************

bysort enacR_0912: sum  dist_roads2008 dist_cities dist_rivers slope elevation  __prec0108 defo_1015 defo_0108 __prec0108 qual if   treecover2000>30 & enacR_0912!=.
bysort NRprotected2000: sum  dist_roads2008 dist_cities dist_rivers slope elevation  __prec0108 defo_1015 defo_0108 __prec0108 qual if   treecover2000>30 & enacR_0912!=.

ttest dist_roads2008 if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ttest dist_cities if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ttest dist_rivers if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ttest slope if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ttest elevation if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ttest qual if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ttest __prec0108 if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ttest defo_0108 if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ttest defo_1015 if   treecover2000>30 & enacR_0912!=., by(enacR_0912)


ksmirnov dist_roads2008 if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ksmirnov dist_cities if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ksmirnov dist_rivers if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ksmirnov slope if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ksmirnov elevation if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ksmirnov qual if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ksmirnov __prec0108 if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ksmirnov defo_0108 if   treecover2000>30 & enacR_0912!=., by(enacR_0912)
ksmirnov defo_1015 if   treecover2000>30 & enacR_0912!=., by(enacR_0912)

tab enacR_0912 if treecover2000>30 

******************************* matching ***************************************

set seed 12345 
gen sortorder = runiform()
sort sortorder

*** 2009 roraima

xi: psmatch2 enacR_09  i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008  if  treecover2000>30 & enacR_09!=. & defo_p0912==.  & ID_state==23, outcome(defo_1015) caliper(0.5) ties ai(3) n(3) common logit odds
foreach var in  _self_defo_1015 _nn  _n1   _id _defo_1015 _weight _support _treated _pscore {
gen roraima`var'=`var'
}
pstest  i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008 , t(enacR_09) mweight(roraima_weight) support (roraima_support) both 

*** 2012 para

xi: psmatch2 enacR_12 i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008 treecoverloss2009 treecoverloss2010 treecoverloss2011  if  treecover2000>30 & enacR_12!=. & defo_p0912==.  & ID_state==14,  outcome(defo_1315)  caliper(0.5) ties ai(1) n(1) norepl common logit odds
foreach var in  _self_defo_1315 _nn  _n1   _id _defo_1315 _weight _support _treated _pscore {
gen para`var'=`var'
}
pstest i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008 treecoverloss2009 treecoverloss2010 treecoverloss2011 , t(enacR_12) mweight(para_weight) support (para_support) both

*** 2010 rondonia

xi: psmatch2 enacRS_10 i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008 treecoverloss2009  if  treecover2000>30 & enacR_10!=. & defo_p0912==.  & ID_state==22 ,   outcome(defo_1115) caliper(0.5) ties ai(1) n(1) norepl common logit odds
foreach var in  _self_defo_1115 _nn  _n1   _id _defo_1115 _weight _support _treated _pscore {
gen rondonia`var'=`var'
}
pstest i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008 treecoverloss2009 , t(enacR_10) mweight(rondonia_weight) support (rondonia_support) both
drop    _id _defo_1115 _weight _support _treated _pscore
mhbounds defo_1115, gamma(1 (0.10) 5) treated(rondonia_treated) weight(rondonia_weight) support(rondonia_support) 

save "...\results_impact.dta", replace




